class: title-slide, right, top background-image: url(data:image/png;base64,#img/moon.JPG) background-position: 90% 75%, 75% 75% background-size:cover .left-column[ # NHS Workshop<br>Introduction to ggplot ] .right-column[ ### Why ggplot **Eugene Hickey**<br> January 21st 2021 ] .palegrey[.left[.footnote[Graphic by [Elaine Hickey](https://photos.google.com/photo/AF1QipMjKNoaxyne8nte4HmxA6Th9-4fUfSbl_mx-_1G)]]] ??? Welcome to the workshop on ggplot. Where we'll show you how to create impressive data visualisations. --- name: about-me layout: false class: about-me-slide, inverse, middle, center # About me <img style="border-radius: 50%;" src="data:image/png;base64,#img/eugene.jpg" width="150px"/> ## Eugene Hickey ### lecturer in physics .fade[Technological University<br>Dublin] [
bioscience.netlify.app](https://bioscience.netlify.app) [
@eugene100hickey](https://twitter.com/eugene100hickey) [
eugene100hickey](https://github.com/eugene100hickey) --- layout: true <a class="footer-link" href="http://intro-ggplot-nhs.netlify.app">intro-ggplot-nhs — Eugene Hickey</a> <!-- this adds the link footer to all slides, depends on footer-link class in css--> --- class: top # Acknowledgments .pull-left-narrow[.center[<img style="border-radius: 50%;" src="data:image/png;base64,#https://www.strategyunitwm.nhs.uk/sites/default/files/styles/banner/public/Sharon_Townsend.jpg?itok=_S1ntVbo" width="100px"/>]] .pull-right-wide[ [Sharon Townsend](https://www.strategyunitwm.nhs.uk/author/sharon-townsend), co-pilot for this workshop and business manager at the NHS, Midlands and Lancashire Strategy Unit. ] -- .pull-left-narrow[.center[ <img style="border-radius: 50%;" src="data:image/png;base64,#https://avatars0.githubusercontent.com/u/53170984?s=200&v=4" width="125px"/>]] .pull-right-wide[ [NHS-R Community](https://nhsrcommunity.com/) for the opportunity to provide this workshop - [NHSRdatasets 📦](https://github.com/nhs-r-community/NHSRdatasets) developed by Chris Mainey and Tom Jemmett ] -- .pull-left-narrow[.center[
]] .pull-right-wide[ - [xaringan 📦](https://github.com/yihui/xaringan#xaringan) developed by Yihui Xie - [flipbookr 📦](https://github.com/EvaMaeRey/flipbookr) developed by Gina Reynolds - [learnr 📦](https://github.com/rstudio/learnr) developed by Garrick Aden-Buie ] --- --- # Target Audience - people with some experience of R, but haven't made the plunge to ggplot. __Just yet__. - do data analysis in R and provide visualisations using base graphics, or something else. --- # Why ggplot? - while some plots can be easier to produce using base graphics .pull-left[ ```r hist(LOS_model$Age) ``` <img src="data:image/png;base64,#day-01-basics_files/figure-html/base_hist-1.png" width="80%" /> ] .pull-right[ ```r ggplot(data = LOS_model, aes(Age)) + geom_histogram(bins = 10) ``` <img src="data:image/png;base64,#day-01-basics_files/figure-html/ggplot_hist-1.png" width="80%" /> ] --- # Why ggplot? - anything moderately complicated is better in ggplot .pull-left[ ```r # David Robinson # http://varianceexplained.org/r/why-I-use-ggplot2/ par(mar = c(1.5, 1.5, 1.5, 1.5)) colors <- 1:6 names(colors) <- unique(top_data$nutrient) # legend approach from http://stackoverflow.com/a/10391001/712603 m <- matrix(c(1:20, 21, 21, 21, 21), nrow = 6, ncol = 4, byrow = TRUE) layout(mat = m, heights = c(.18, .18, .18, .18, .18, .1)) top_data$combined <- paste(top_data$name, top_data$systematic_name) for (gene in unique(top_data$combined)) { sub_data <- filter(top_data, combined == gene) plot(expression ~ rate, sub_data, col = colors[sub_data$nutrient], main = gene) for (n in unique(sub_data$nutrient)) { m <- lm(expression ~ rate, filter(sub_data, nutrient == n)) if (!is.na(m$coefficients[2])) { abline(m, col = colors[n]) } } } # create a new plot for legend plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") legend("top", names(colors), col = colors, horiz = TRUE, lwd = 4) ``` ] .pull-right[ <!-- --> ] --- # Why ggplot? - anything moderately complicated is better in ggplot .pull-left[ ```r ggplot(top_data, aes(rate, expression, color = nutrient)) + geom_point(show.legend = FALSE) + geom_smooth(method = "lm", se = FALSE, show.legend = FALSE) + facet_wrap(~systematic_name, scales = "free_y") ``` ] .pull-right[ <!-- --> ] --- # Lots of addin packages for ggplot gg.gap, ggallin, ggalluvial, ggalt, ggamma, gganimate, ggasym, ggbeeswarm, ggBubbles, ggbuildr, ggbump, ggcharts, ggChernoff, ggconf, ggcorrplot, ggdag, ggdark, ggDCA, ggdemetra, ggdendro, ggdist, ggdmc, gge, ggeasy, ggedit, ggeffects, ggenealogy, ggetho, ggExtra, ggfan, ggfittext, ggfocus, ggforce, ggformula, ggfortify, gggap, gggenes, ggghost, gggibbous, ggguitar, gghalfnorm, gghalves, gghighlight, ggimage, ggimg, gginference, gginnards, ggip, ggiraph, ggiraphExtra, ggjoy, gglasso, gglm, gglogo, ggloop, gglorenz, ggm, ggmap, ggmcmc, ggmix, ggmosaic, ggmr, ggmsa, ggmuller, ggmulti, ggnetwork, ggnewscale, ggnormalviolin, ggnuplot, ggpacman, ggpage, ggparallel, ggparliament, ggparty, ggperiodic, ggplot.multistats, ggplot2, ggplot2movies, ggplotAssist, ggplotgui, ggplotify, ggplotlyExtra, ggpmisc, ggPMX, ggpointdensity, ggpol, ggpolypath, ggpubr, ggpval, ggQC, ggQQunif, ggquickeda, ggquiver, ggRandomForests, ggraph, ggraptR, ggrasp, ggrastr, ggrepel, ggResidpanel, ggridges, ggrisk, ggROC, ggroups, ggsci, ggseas, ggseqlogo, ggsignif, ggsn, ggsoccer, ggsolvencyii, ggsom, ggspatial, ggspectra, ggstance, ggstar, ggstatsplot, ggstudent, ggswissmaps, ggtern, ggtext, ggThemeAssist, ggthemes, ggTimeSeries, ggupset, ggVennDiagram, ggversa, ggvis, ggvoronoi, ggwordcloud --- # And others, that make ggplots that can then be modified and treated as such .pull-left[ ```r fviz_cluster_example ``` <!-- --> ] .pull-right[ ```r fviz_cluster_example + theme_classic() ``` <!-- --> ] --- # Other reasons - ggplot is easy to make publication-ready - easier to make sequence of visualisations